package com.yourcompany.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yourcompany.api.entity.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {

    /**
     * 获取用户的所有权限ID
     */
    @Select("SELECT DISTINCT rp.permission_id FROM role_permission rp " +
            "INNER JOIN user_role ur ON ur.role_id = rp.role_id " +
            "WHERE ur.user_id = #{userId} AND ur.is_deleted = 0 AND rp.is_deleted = 0")
    List<Long> getPermissionIdsByUserId(@Param("userId") Long userId);

    /**
     * 获取角色的所有权限ID
     */
    @Select("SELECT permission_id FROM role_permission " +
            "WHERE role_id = #{roleId} AND is_deleted = 0")
    List<Long> getPermissionIdsByRoleId(@Param("roleId") Long roleId);
} 